import {baseEffects, baseReducers, baseState} from "../../../../../models/baseModel";

export default {
  namespace: 'datachart',

  state: {
    ...baseState,
    deviceInfo: {},
    chartData: [],
    uploadStatistics: [],
  },

  reducers: {
    ...baseReducers
  },

  effects: {

    ...baseEffects,

    * getData({payload}, {put, call}) {

      try {
        const data = [];
        for (let i = 0; i < 50; i++) {
          data.push({
            // year: moment(result[i].time).format("YYYY-MM-DD HH:mm:ss"),
            time: 1583331319 - i * 1000 * 60 * 60 * 24,
            value: Number(Math.random()*100)
          });
        }

        yield put({
          type: 'initState',
          payload: {chartData: data}
        });
      } catch (error) {
        console.error("getData", error);
        yield put({type: 'loadError'});
      }
    },

  }

}

function getBaseUrl() {
  return "/device";
}

